<template>
  <el-dialog
    v-model="visible"
    v-if="visible"
    title="编辑"
    width="20%"
    top="250px"
    :before-close="handleClose"
  >
    <el-form ref="formRef" :model="formData" label-width="120px" class="form-container">
      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="工单号" prop="creator">
            <el-input v-model="formData.id" disabled placeholder="请输入工单号" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="利润" prop="profit">
            <el-input v-model="formData.profit" placeholder="请输入利润" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="回款金额" prop="paymentAmount">
            <el-input v-model="formData.paymentAmount" placeholder="请输入回款金额" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleSubmit">提交</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, defineEmits, watch, defineProps, reactive } from 'vue'
import * as ticketManagementApi from '@/api/ticketManagement/index'
import { ElMessage } from 'element-plus'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
const props = defineProps({
  type: {
    type: String,
    default: 'add'
  },
  options: {
    type: Object,
    default: {}
  }
})
const userData = ref()
onMounted(() => {})
const title = ref('')
// 定义表单初始数据
const initFormData = {}

// 表单数据
const formData = ref({ id: '', status: '' })
// 表单引用
const formRef = ref(null)
// 弹窗可见性
const visible = ref(false)
// 定义事件
const emit = defineEmits(['onClose', 'onSubmit'])

// 打开弹窗方法
const onOpen = (data) => {
  console.log('data', data)
  visible.value = true
  formData.value.id = data.id
}

// 关闭弹窗
const handleClose = () => {
  visible.value = false
  nextTick(() => {
    emit('onClose')
  })
}
// 提交表单
const handleSubmit = () => {
  formData.value.status = 4
  ticketManagementApi.editWorkorder(formData.value).then((res) => {
    ElMessage.success('修改成功')
  })
  setTimeout(() => {
    emit('onSubmit')
  }, 500)
  handleClose()
}

// 暴露打开弹窗的方法
defineExpose({ onOpen })
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-container {
  width: 40%;
  max-width: 1200px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}

.close-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.form-container {
  width: 100%;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style>
